/**
 * BaseActivity.java
 */
package com.totobox.apps.activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.totobox.apps.Const;
import com.totobox.apps.R;
import com.totobox.apps.common.MoveActivity;

/**
 * @author gundallove
 * @email gundallove@gmail.com
 */
public class BasicActivity extends Activity implements OnClickListener , OnItemClickListener {
	
	//title zone
	protected ImageButton btn_title_right;
	protected ImageButton btn_title_left;
	
	protected LinearLayout searchMenu;
	protected LinearLayout topMenu;
	
	public Activity cActivity;
	
	protected ImageButton footer_menu_01;
	protected ImageButton footer_menu_02;
	protected ImageButton footer_menu_03;
	protected ImageButton footer_menu_04;
	protected ImageButton footer_menu_05;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	 }
	
	/* (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	public void onClick(View v) {}
	
	/* (non-Javadoc)
	 * @see android.widget.AdapterView.OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long)
	 */
	public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {}
	
	/**
	 * <pre>
	 * 메세지 출력
	 * @param ctx
	 * @param msg
	 * void
	 * </pre>
	 */
	public void showText(Context ctx , String msg){
		Toast.makeText(ctx, msg , Toast.LENGTH_SHORT).show();
	}
	
	/**
	 * 메세지 출력
	 * @param ctx
	 * @param msg
	 * @param field
	 */
	public void showText(Context ctx , String msg , int field){
		Toast.makeText(ctx, msg , field).show();
	}
	
	/**
	 * 타이틀 초기화
	 */
	public void initTitle(){
		//===========타이틀 영역===========
        btn_title_left = (ImageButton)findViewById(R.id.btn_title_left);
        btn_title_right = (ImageButton)findViewById(R.id.btn_title_right);
        btn_title_right.setOnClickListener(this);
        btn_title_left.setOnClickListener(this);
        btn_title_right.setClickable(false);
        //===========타이틀 영역===========
	}
	
	/**
	 * 검색 메뉴
	 * @return
	 */
	public View setLayoutTopMenu(final Activity cActivity){
		
		 //현재 액티비티
		this.cActivity = cActivity;
        
		LayoutInflater inflater = getLayoutInflater();
		View v = inflater.inflate(R.layout.layout_top_menu, null);
		
		//사진 메뉴
		ImageView pic = (ImageView)v.findViewById(R.id.btn_picture);
		//동영상
		ImageView mov = (ImageView)v.findViewById(R.id.btn_movie);
		//음악
		ImageView mic = (ImageView)v.findViewById(R.id.btn_music);
		//기타
		ImageView etc = (ImageView)v.findViewById(R.id.btn_etc);
		
		if("IMG".equals(Const.MENU)) pic.setImageDrawable(getResources().getDrawable(R.drawable.btn_01_over));
		else if("VOD".equals(Const.MENU)) mov.setImageDrawable(getResources().getDrawable(R.drawable.btn_02_over));
		else if("AUD".equals(Const.MENU)) mic.setImageDrawable(getResources().getDrawable(R.drawable.btn_03_over));
		else if("ETC".equals(Const.MENU)) etc.setImageDrawable(getResources().getDrawable(R.drawable.btn_04_over));
		pic.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Const.MENU = "IMG";
				moveActivity(cActivity);
			}
		});
		
		mov.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Const.MENU = "VOD";
				moveActivity(cActivity);
			}
		});
		
		mic.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Const.MENU = "AUD";
				moveActivity(cActivity);
			}
		});
		
		etc.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Const.MENU = "ETC";
				moveActivity(cActivity);
			}
		});
		
		return v;
	}
	
	/**
	 * 액티비티 이동
	 * @param cActivity
	 */
	public void moveActivity(Activity cActivity){
		
		// TODO Auto-generated method stub
		MoveActivity go = null;
		Class cls = null;
		
		if(cActivity instanceof MyStorageActivity){
			cls = MyStorageActivity.class;
		}
		else{
			cls = MyTotoFolderActivity.class;
		}
		
		//마이 토토 메인 페이지는 살린다.
		if(cActivity instanceof MyTotoActivity){
			go = new MoveActivity(cActivity, MyTotoFolderActivity.class);
			go.startActivity();
		}
		else{
			go = new MoveActivity(cActivity, cls);	
			go.startActivity(cActivity);
		}
	}
	
	/**
	 * 상단 검색 메뉴 추가
	 */
	public void showTopMenu(final Activity cActivity){
		topMenu = (LinearLayout) findViewById(R.id.layout_top_menu);
		topMenu.addView(setLayoutTopMenu(cActivity));
	}
	
	/**
	 * 검색 메뉴
	 * @return
	 */
	public View setLayoutSearch(){
		LayoutInflater inflater = getLayoutInflater();
		View v = inflater.inflate(R.layout.layout_search, null);
		ImageView search = (ImageView)v.findViewById(R.id.btn_search);
		search.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		
		return v;
	}
	
	/**
	 * 상단 검색 메뉴 추가
	 */
	public void showSearchMenu(){
		searchMenu = (LinearLayout) findViewById(R.id.layout_search);
		searchMenu.addView(setLayoutSearch());
		
	}
	
	/**
	 * 하위메뉴 초기화
	 */
	public void setFooterMenu(final Activity act){
		
		//===========footer 영역===========
		footer_menu_01 = (ImageButton)findViewById(R.id.footer_menu_01);
		footer_menu_02 = (ImageButton)findViewById(R.id.footer_menu_02);
		footer_menu_03 = (ImageButton)findViewById(R.id.footer_menu_03);
		footer_menu_04 = (ImageButton)findViewById(R.id.footer_menu_04);
		footer_menu_05 = (ImageButton)findViewById(R.id.footer_menu_05);
		
		
		if(act instanceof MyTotoFolderActivity || act instanceof TotoFileDtailActivity){
			footer_menu_01.setImageDrawable(getResources().getDrawable(R.drawable.footer_btn_01_over));
		}
		else if(act instanceof MyFavoriteActivity) footer_menu_02.setImageDrawable(getResources().getDrawable(R.drawable.footer_btn_02_over));
		else if(act instanceof MyStorageActivity) footer_menu_03.setImageDrawable(getResources().getDrawable(R.drawable.footer_btn_03_over));
		else if(act instanceof TotoFunActivity) footer_menu_04.setImageDrawable(getResources().getDrawable(R.drawable.footer_btn_04_over));
		else if(act instanceof TotoSettingActivity || act instanceof TotoNoticeDetailActivity || act instanceof TotoNoticeListActivity){ 
			footer_menu_05.setImageDrawable(getResources().getDrawable(R.drawable.footer_btn_05_over));
		}
		
		footer_menu_01.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Const.MENU = "IMG";
				new MoveActivity(act, MyTotoFolderActivity.class).startActivity(act);	//내자료
			}});
		footer_menu_02.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				new MoveActivity(act, MyFavoriteActivity.class).startActivity(act);	//즐겨찾기
			}});
		footer_menu_03.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Const.MENU = "IMG";
				new MoveActivity(act, MyStorageActivity.class).startActivity(act);	//보관함
			}});
		footer_menu_04.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				new MoveActivity(act, TotoFunActivity.class).startActivity(act);	//토토펀
			}});
		footer_menu_05.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				new MoveActivity(act, TotoSettingActivity.class).startActivity(act);	//설정
			}});
		//===========footer 영역===========
	}
}
